import sys
sys.path.append('../kernel')
from model import Model
class Xcurl_3(Model):
    table='city_hotel_xcurl_3'
    def __init__(self):
        # 链接数据库
        super().__init__()

    # 添加城市酒店url
    def add_city_hotel_url(self, url, cid, xcurl_1_id):
        sql = "INSERT INTO " + self.table + " SET `url`='%s',cid='%d',xcurl_2_id='%d'" % (url, cid, xcurl_1_id)
        self.cursor.execute(sql)
        self.conn.commit()  # 提交
    #获取第2层url
    # def get_xcurl_by_id(self,id):
    #     sql="SELECT id,url,cid,xcurl_2_id FROM "+self.table+" WHERE id>'%d' LIMIT 1" % id
    #     self.cursor.execute(sql)
    #     data=self.cursor.fetchone()
    #     return data

    # 根据url获取信息
    def get_xcurl_by_url(self,url):
        sql = "SELECT id,url,cid,xcurl_2_id FROM " + self.table + " WHERE url='%s'" % url
        self.cursor.execute(sql)
        data = self.cursor.fetchone()
        return data

    # 查询酒店url
    def get_xcurl_by_id(self,id):
        sql = "SELECT id,url,cid FROM " + self.table + " WHERE id>'%d' LIMIT 3" % id
        self.cursor.execute(sql)
        data = self.cursor.fetchall()
        return data

    def __del__(self):
        #计数数据库链接
        self.cursor.close()
        self.conn.close()

